package com.dfa.nypl.common;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;

public class PopupPanel {
	private View popup;
	public boolean isVisible = false;
	private MapView mapview;
	private Activity activity;

	public PopupPanel(int layout, MapView m, Activity c) {
		this.activity = c;
		this.mapview = m;
		ViewGroup parent = (ViewGroup) mapview.getParent();

		popup = activity.getLayoutInflater().inflate(layout, parent, false);

		// popup.setOnClickListener(new View.OnClickListener() {
		// public void onClick(View v) {
		// hide();
		// }
		// });
	}

	public View getView() {
		return (popup);
	}

	public void show(GeoPoint point) {

		MapView.LayoutParams screenLP = new MapView.LayoutParams(
				MapView.LayoutParams.WRAP_CONTENT,
				MapView.LayoutParams.WRAP_CONTENT, point,
				MapView.LayoutParams.BOTTOM_CENTER);

		hide();

		mapview.addView(popup, screenLP);

		isVisible = true;
	}

	public void show(GeoPoint point, int x, int y) {
		MapView.LayoutParams screenLP = new MapView.LayoutParams(
				MapView.LayoutParams.WRAP_CONTENT,
				MapView.LayoutParams.WRAP_CONTENT, point, x, y,
				MapView.LayoutParams.BOTTOM_CENTER );
		hide();

		mapview.addView(popup, screenLP);

		isVisible = true;
	}

	public void hide() {
		if (isVisible) {
			isVisible = false;
			((ViewGroup) popup.getParent()).removeView(popup);
		}
	}
}
